<template>
  <el-form :model="tableForm" :rules="tableRule" ref="tableForm" label-width="120px">

    <el-row>
      <el-col :span="20">
        <el-form-item label="卡号" prop="account">
          <el-input size="small" v-model="tableForm.account" auto-complete="off" placeholder="请输入卡号"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="4">
        <el-popover placement="right" trigger="click" v-model="visible">
          <Selector @getSelectorData="getSelectorData"></Selector>
          <el-button slot="reference">选择</el-button>
        </el-popover>
      </el-col>
    </el-row>

    <el-form-item label="身高(cm)" prop="height">
      <el-input size="small" v-model="tableForm.height" auto-complete="off" placeholder="请输入身高(cm)"></el-input>
    </el-form-item>

    <el-form-item label="体重(kg)" prop="weight">
      <el-input size="small" v-model="tableForm.weight" auto-complete="off" placeholder="请输入体重(kg)"></el-input>
    </el-form-item>

    <el-form-item label="血压(mmHg)">
      <el-col :span="12">
        <el-input size="small" v-model="tableForm.lowPressure" auto-complete="off"
                  placeholder="请输入低压(mmHg)"></el-input>
      </el-col>
      <el-col class="line" :span="0.1">&#45;&#45;</el-col>
      <el-col :span="11">
        <el-input size="small" v-model="tableForm.highPressure" auto-complete="off"
                  placeholder="请输入高压(mmHg)"></el-input>
      </el-col>
    </el-form-item>

    <el-form-item label="血糖(mmol/L)" prop="glucose">
      <el-input size="small" v-model="tableForm.glucose" auto-complete="off"
                placeholder="请输入血糖(mmol/L)"></el-input>
    </el-form-item>

    <el-form-item label="心率(次/分)" prop="heart">
      <el-input size="small" v-model="tableForm.heart" auto-complete="off" placeholder="请输入心率(次/分)"></el-input>
    </el-form-item>


    <el-descriptions title="血常规化验项目类">
    </el-descriptions>
    <el-form-item label="红细胞" prop="erythrocyte">
      <el-input style="width:80%" size="small" v-model="tableForm.erythrocyte" auto-complete="off"
                placeholder="请输入红细胞">
      </el-input>
      <span>* 10^12/L</span>
    </el-form-item>

    <el-form-item label="血红蛋白(g/L)" prop="hemoglobin">
      <el-input size="small" v-model="tableForm.hemoglobin" auto-complete="off"
                placeholder="请输入血红细胞(g/L)"></el-input>
    </el-form-item>

    <el-form-item label="白细胞" prop="leukocyte">
      <el-input style="width:80%" size="small" v-model="tableForm.leukocyte" auto-complete="off"
                placeholder="请输入白细胞"></el-input>
      <span>* 10^9/L</span>
    </el-form-item>

    <el-form-item label="中性粒细胞比率(%)" prop="Neutrophils">
      <el-input size="small" v-model="tableForm.Neutrophils" auto-complete="off"
                placeholder="请输入中性粒细胞比率(%)"></el-input>
    </el-form-item>

    <el-form-item label="淋巴细胞" prop="LYM">
      <el-input style="width:80%" size="small" v-model="tableForm.lymphocyte" auto-complete="off"
                placeholder="请输入淋巴细胞"></el-input>
      <span>* 10^9/L</span>
    </el-form-item>

    <el-form-item label="血小板" prop="platelet">
      <el-input style="width:80%" size="small" v-model="tableForm.platelet" auto-complete="off"
                placeholder="请输入血小板"></el-input>
      <span>* 10^9/L</span>
    </el-form-item>

    <el-descriptions title="血脂化验项目类">
    </el-descriptions>
    <el-form-item label="总胆固醇(mmol/L)" prop="total_cholesterol">
      <el-input size="small" v-model="tableForm.total_cholesterol" auto-complete="off"
                placeholder="请输入总胆固醇(mmol/L)">
      </el-input>
    </el-form-item>

    <el-form-item label="甘油三酯(mmol/L)" prop="Triglycerides">
      <el-input size="small" v-model="tableForm.Triglycerides" auto-complete="off" placeholder="请输入甘油三酯(mmol/L)">
      </el-input>
    </el-form-item>

    <el-form-item label="低密度脂蛋白胆固醇(mmol/L)" prop="LDL-cholesterol">
      <el-input size="small" v-model="tableForm.LDL-cholesterol" auto-complete="off"
                placeholder="请输入低密度脂蛋白胆固醇(mmol/L)">
      </el-input>
    </el-form-item>

    <el-form-item label="高密度脂蛋白胆固醇(mmol/L)" prop="HDL_cholesterol">
      <el-input size="small" v-model="tableForm.HDL_cholesterol" auto-complete="off"
                placeholder="请输入高密度脂蛋白胆固醇(mmol/L)">
      </el-input>
    </el-form-item>

    <el-descriptions title="肝功能项目类">
    </el-descriptions>
    <el-form-item label="谷丙转氨酶(U/L)" prop="alanine_transaminase">
      <el-input size="small" v-model="tableForm.alanine_transaminase" auto-complete="off"
                placeholder="请输入谷丙转氨酶(U/L)">
      </el-input>
    </el-form-item>

    <el-form-item label="谷草转氨酶(U/L)" prop="aspartate_aminotransferase">
      <el-input size="small" v-model="tableForm.aspartate_aminotransferase" auto-complete="off"
                placeholder="请输入谷草转氨酶(U/L)">
      </el-input>
    </el-form-item>

    <el-form-item label="血清胆红素">
    </el-form-item>
    <el-form-item label="总胆红素(μ mol/L)" prop="total_bilirubin">
      <el-input size="small" v-model="tableForm.total_bilirubin" auto-complete="off"
                placeholder="请输入总胆红素(μ mol/L)">
      </el-input>
    </el-form-item>

    <el-form-item label="直接胆红素(mmol/L)" prop="total_bilirubin_direct">
      <el-input size="small" v-model="tableForm.total_bilirubin_direct" auto-complete="off"
                placeholder="请输入直接胆红素(mmol/L)">
      </el-input>
    </el-form-item>

    <el-descriptions title="尿液功能项目类">
    </el-descriptions>
    <el-form-item label="尿蛋白" prop="pro">
      <el-select size="small" v-model="tableForm.pro" auto-complete="off" placeholder="请选择">
        <el-option label="阴性" value="0"></el-option>
        <el-option label="阳性" value="1"></el-option>
      </el-select>
    </el-form-item>

    <el-form-item label="尿葡萄糖" prop="glu">
      <el-select size="small" v-model="tableForm.glu" auto-complete="off" placeholder="请选择">
        <el-option label="阴性" value="0"></el-option>
        <el-option label="阳性" value="1"></el-option>
      </el-select>
    </el-form-item>

    <el-form-item label="尿胆红素" prop="bil">
      <el-select size="small" v-model="tableForm.bil" auto-complete="off" placeholder="请选择">
        <el-option label="阴性" value="0"></el-option>
        <el-option label="阳性" value="1"></el-option>
      </el-select>
    </el-form-item>

    <el-form-item label="尿胴体" prop="ket">
      <el-select size="small" v-model="tableForm.ket" auto-complete="off" placeholder="请选择">
        <el-option label="阴性" value="negative"></el-option>
        <el-option label="阳性" value="positive"></el-option>
      </el-select>
    </el-form-item>

    <el-form-item label="尿沉渣镜检" prop="bilirubin">
      <el-input size="small" v-model="tableForm.wbc" auto-complete="off" placeholder="请输入白细胞(/HP)">
      </el-input>
      <el-input size="small" v-model="tableForm.rbc" auto-complete="off" placeholder="请输入红细胞(/HP)">
      </el-input>
    </el-form-item>

    <el-form-item label="尿胆原" prop="uro">
      <el-select size="small" v-model="tableForm.uro" auto-complete="off" placeholder="请选择">
        <el-option label="阴性" value="negative"></el-option>
        <el-option label="阳性" value="positive"></el-option>
      </el-select>
    </el-form-item>

    <el-form-item label="尿比重" prop="sg">
      <el-input size="small" v-model="tableForm.sg" auto-complete="off" placeholder="请输入尿比重">
      </el-input>
    </el-form-item>

    <el-form-item label="尿酸碱度" prop="ph">
      <el-input size="small" v-model="tableForm.ph" auto-complete="off" placeholder="请输入尿酸碱度">
      </el-input>
    </el-form-item>

    <el-descriptions title="肿瘤类">
    </el-descriptions>
    <el-form-item label="甲胎蛋白" prop="afp">
      <el-input size="small" v-model="tableForm.afp" auto-complete="off" placeholder="请输入甲胎蛋白(ng/ml)">
      </el-input>
    </el-form-item>

    <el-form-item label="癌胚抗原" prop="cea">
      <el-input size="small" v-model="tableForm.cea" auto-complete="off" placeholder="请输入癌胚抗原(ng/ml)">
      </el-input>
    </el-form-item>

    <el-form-item label="铁蛋白" prop="Fer">
      <el-input size="small" v-model="tableForm.fer" auto-complete="off" placeholder="请输入铁蛋白(ng/ml)">
      </el-input>
    </el-form-item>


  </el-form>
</template>

<script>

import {addData, updateData} from '@/api/physical'
import Selector from '../user/selector'

// 表单校验
const tableRule = {
  account: [{required: true, message: '请输入卡号', trigger: 'blur'}],
  height: [{required: true, message: '请输入身高(cm)', trigger: 'blur'}],
  weight: [{required: true, message: '请输入体重(kg)', trigger: 'blur'}],
  lowPressure: [{required: true, message: '请输入低压(mmHg)', trigger: 'blur'}],
  highPressure: [{required: true, message: '请输入高压(mmHg)', trigger: 'blur'}],
  glucose: [{required: true, message: '请输入血糖(mmol/L)', trigger: 'blur'}],
  heart: [{required: true, message: '请输入心率(次/分)', trigger: 'blur'}],
  // erythrocyte:[{required: false, message: '请输入红细胞', trigger: 'blur'}]
};

export default {
  name: 'PhysicalEdit',
  props: {
    formData: {
      type: Object
    }
  },
  data() {
    return {
      tableForm: this.formData,
      tableRule: tableRule,
      visible: false,
    }
  },
  components: {
    Selector
  },
  methods: {
    //表单保存事件
    submitForm() {
      this.$refs["tableForm"].validate(valid => {
        if (valid) {
          if (this.tableForm.id == "") {
            addData(this.tableForm).then(res => {
              if (res.message == "success") {
                this.$message({
                  type: 'success',
                  message: '新增成功！'
                });
                this.$emit("closeDialog", false);
              } else {
                this.$message({
                  type: 'info',
                  message: res.message
                });
              }
            });
          } else {
            updateData(this.tableForm).then(res => {
              if (res.message == "success") {
                this.$message({
                  type: 'success',
                  message: '修改成功！'
                });
                this.$emit("closeDialog", false);
              } else {
                this.$message({
                  type: 'info',
                  message: res.message
                });
              }
            });
          }
        } else {
          return false;
        }
      });
    },
    // 选择父表数据
    getSelectorData(v) {
      this.visible = false
      this.tableForm.account = v[0].account
      this.tableForm.userId = v[0].id
    },
    clearForm() {
      this.$refs.tableForm.resetFields();
      this.$refs.tableForm.clearValidate();
    }
  }
}
</script>

<style scoped>


</style>
